package com.example.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class CloudFragment extends ListFragment{

private String[] data=new String[]{"2017.04.1","2017.04.1","2017.04.1","2017.04.4","2017.04.5"};
    private String[]time={"01:00","02:00","03:00","04:00","04:00"};
    private String[]value={"伺服阀","阿德飒飒","秦阿房宫","阿斯弗","全微分"};
    private  ListView listView;
    private MyAdapter adapter = null;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.cloud, container,false);
//        listView=(ListView) view.findViewById();
//
//        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(getContext(),android.R.layout.simple_list_item_1,data);
//        listView.setAdapter(arrayAdapter);
        return view;
    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
//         MyAdapter adapter=new MyAdapter(this);
       String duibi = null;
        super.onCreate(savedInstanceState);
        List<Map<String,Object>> listITEMS= new ArrayList<Map<String,Object>>();

        for(int i=0;i<data.length;i++){
            if( duibi == data[i]){
                data[i]="";
            }else {
                duibi=data[i];
            }
            Map<String,Object>listITEM=new HashMap<String,Object>();
            listITEM.put("time",time[i]);
            listITEM.put("data",data[i]);
            listITEM.put("value",value[i]);
            listITEMS.add(listITEM);
        }
        SimpleAdapter simpleAdapter=new SimpleAdapter(getContext(),listITEMS,
                R.layout.item_view,
                new String[]{"data","value","time"},
                new int[]{
                        R.id.show_data,
                        R.id.show_value,
                        R.id.show_time});
        setListAdapter(simpleAdapter);
//        adapter=new MyAdapter(getContext());
//        setListAdapter(adapter);
    }

    @Override
    public void onListItemClick(ListView l, View v, int position, long id) {
        System.out.println("Click On List Item!!!");

        super.onListItemClick(l, v, position, id);
    }
}